package com.vogue.meeting.controller;

import com.vogue.meeting.common.aop.annotation.Repeat;
import com.vogue.meeting.common.context.UserContext;
import com.vogue.meeting.common.web.domain.Result;
import com.vogue.meeting.fluent.dao.intf.UserDao;
import com.vogue.meeting.fluent.entity.UserEntity;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户
 */
@Slf4j
@Api(tags = {"用户"})
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserContext userContext;
    @Autowired
    private UserDao userDao;


    @Repeat
    @PostMapping(value = "/signUp", produces = "application/json;charset=UTF-8")
    public Result signUp(@RequestBody UserEntity user){
        return userDao.signUp(user);
    }

    @PreAuthorize("hasRole('ROLE_API')")
    @PostMapping(value = "/info", produces = "application/json;charset=UTF-8")
    public Result info(){
        UserEntity user = userDao.selectById(userContext.getId());
        return Result.success(user);
    }

}
